#ifndef HTTPCLIENT_H
#define HTTPCLIENT_H

#include <QObject>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <QTimer>
#include <QSslConfiguration>
#include <QString>
#include <QByteArray>

//http请求类
class HttpClient : public QObject
{
    Q_OBJECT
public:
    explicit HttpClient(QObject *parent = 0);
    void sendRequest_Get(const QString& strUrl,int userData = 0);//根据url发起http的GET请求
    void sendRequest_Post(const QString& strUrl,QByteArray & bufContent,int userData = 0);//根据url发起http的POST请求

signals:
    void signal_requestFinished(int,bool bSuccess,const QString& strResult,int); //http请求结束

public slots:
    void slot_requestFinished(); //http请求结束
    void slot_requestTimeout();  //请求超时

private:
    QNetworkAccessManager* m_pNetworkManager;//网络管理类
    QNetworkReply* m_pNetworkReply; //封装请求返回信息
    QTimer* m_pTimer; //请求超时计时器
    QString m_strUrl; //记录当前请求的url
    int m_nType;//1:Get;2:Post
    int m_userData;
};

#endif // HTTPCLIENT_H
